package com.hzspace.applicationrunner;

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;
import java.util.Set;

/**
 * @Author: LiuHao
 * @Descirption:
 * @Date: 2020/3/1_17:05
 */
@Component
@Order(60)
public class MyApplicationRunner1 implements ApplicationRunner {
    /**/

    /**
     * 打包运行传参测试
     *
     * java -jar 20-spring-boot-applicationrunner-0.0.1-SNAPSHOT.jar --name=lh --age=25 www.hzspace.top hahaha
     *
     */


    @Override
    public void run(ApplicationArguments args) throws Exception {
        System.out.println("MyApplicationRunner1开始》》》》》》》》》");
        String[] sourceArgs = args.getSourceArgs();//所有参数
        System.out.println("所有参数:"+Arrays.toString(sourceArgs));
        List<String> nonOptionArgs = args.getNonOptionArgs();//无Key参数
        System.out.println("无Key参数:"+nonOptionArgs);
        Set<String> optionNames = args.getOptionNames();//Key Value参数
        for (String optionName : optionNames) {
            List<String> optionValueList = args.getOptionValues(optionName);
            System.out.println("有Key参数 Key:"+optionName+"Value:"+optionValueList);
        }
        System.out.println("MyApplicationRunner1结束》》》》》》》》》");
    }
}
